package com.xhs.main.controller.cwb;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xhs.main.service.cwb.impl.CwbMarketServiceImpl;
import com.xhs.main.service.cwb.impl.CwbRefundServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * create by ljw on 2020/10/22
 */
@Controller
public class IncomeController {

    //自动注入对象
    @Autowired
    CwbRefundServiceImpl cwbRefundService;

    @Autowired
    CwbMarketServiceImpl cwbMarketService;

    //退款
    @RequestMapping("/refund")
    @ResponseBody
    public String getRefund(){
        List<Map<String,Object>> mapList = new ArrayList<>();
        Map<String,Object> map1 = new HashMap<>();
        Map<String,Object> map2 = new HashMap<>();
        Map<String,Object> map3 = new HashMap<>();
        Map<String,Object> map4 = new HashMap<>();
        Map<String,Object> map5 = new HashMap<>();
        Map<String,Object> map6 = new HashMap<>();
        Map<String,Object> map7 = new HashMap<>();
        Map<String,Object> map8 = new HashMap<>();
        map1.put("name","腾讯");
        map1.put("value",cwbRefundService.getAllMoney("腾讯"));
        map2.put("name","小米");
        map2.put("value",cwbRefundService.getAllMoney("小米"));
        map3.put("name","华为");
        map3.put("value",cwbRefundService.getAllMoney("华为"));
        map4.put("name","谷歌");
        map4.put("value",cwbRefundService.getAllMoney("谷歌"));
        map5.put("name","阿里巴巴");
        map5.put("value",cwbRefundService.getAllMoney("阿里巴巴"));
        map6.put("name","字节跳动");
        map6.put("value",cwbRefundService.getAllMoney("字节跳动"));
        map7.put("name","快手");
        map7.put("value",cwbRefundService.getAllMoney("快手"));
        map8.put("name","抖音");
        map8.put("value",cwbRefundService.getAllMoney("抖音"));
        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        mapList.add(map4);
        mapList.add(map5);
        mapList.add(map6);
        mapList.add(map7);
        mapList.add(map8);
        System.out.println(mapList);
        //返回的数据
        String json = JSONArray.toJSONString(mapList);
        return json;
    }

    //销售额统计
    @RequestMapping("/xiaoshou")
    @ResponseBody
    public String getXiaoshou(){
        List<Map<String,Object>> mapList = new ArrayList<>();

        for(int i = 1;i < 10 ; i++){
            Map<String,Object> map = new HashMap<>();
            map.put("name","A"+i);
            map.put("value",cwbMarketService.getmoney(i+"-12"));
            mapList.add(map);
        }
        //返回的数据
        String json = JSONArray.toJSONString(mapList);
        return json;
    }
}
